package com.apes.scm.account.account.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;

import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.stock.model.Location;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * Created by ASUS on 2018-01-24.
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = DetailOfLend.CONST_TABLE_NAME,
    indexes = {@Index(name = "I_ACC_DETAILED_OF_LEND_01", unique = true,
            columnList = "LOCATION_ID,PRODUCT_ID,PERSON_ID")}
)
public class DetailOfLend extends Model {
    public static final String CONST_TABLE_NAME = "acc_detail_of_lend";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "保管数明细卡片账")
    @Comment("内码")
    private Long id; //内码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "LOCATION_ID", referencedColumnName = "id", nullable = false)
    @Comment("仓库库区编码")
    private Location location;  //仓库库区编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "id", nullable = false)
    @Comment("商品编码")
    private Product product;  //商品编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PERSON_ID", referencedColumnName = "id", nullable = false)
    @Comment("借出人")
    private PartyRole person;  //借出人

    @Column(name = "LEND_TYPE", nullable = false, length = 256)
    @Comment("借出类型")
    private String lendType;  //借出类型

    @Column(name = "LEND_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("借出数量")
    private double lendQty = 0.0;  //借出数量

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COMPANY_ID", referencedColumnName = "id", nullable = false)
    @Comment("公司编码")
    private PartyRole company;  //公司编码

}
